package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogEnterNameActivityRank;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogEnterNameDaoImpl extends TempDao {

    public boolean addLogEnterNameActivityRankList(List<LogEnterNameActivityRank> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getChannelServerDb());
        String sql = "INSERT INTO t_n_log_enter_name_rank(activityId,conditionType,groupId,rank,rankId,zoneId,updateTime,logTime) VALUES(?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogEnterNameActivityRank data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getConditionType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getRank()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getRankId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getZoneId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUpdateTime()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getLogTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
